﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ServiceController
{

    public delegate List<Entities.Storage_Account.StorageAccount> StorageAccountListDelegate(String SubscriptionID, String CertificatePath);
    public partial class ServiceController
    {
        StorageAccountListDelegate _StorageAccountListDelegate;
        public List<Entities.Storage_Account.StorageAccount> GetStorageAccountList(String SubscriptionID, String CertificatePath)
        {

            List<Entities.Storage_Account.StorageAccount> list = new List<Entities.Storage_Account.StorageAccount>();
            DataAccess.DataAccess da = new DataAccess.DataAccess();
            list = da.GetStorageAccountList(SubscriptionID, CertificatePath);
            return list;



            //try
            //{
            //    list = da.GetStorageAccountList(SubscriptionID, CertificatePath);
            //    OnGetStorageAccountListCompleted(new ServiceControllerEventArgs() { StorageAccountList = list });
            //}
            //catch (Exception ex)
            //{
            //    OnGetStorageAccountListCompleted(new ServiceControllerEventArgs() { error = ex });

            //}
        }

        public void GetStorageAccountListAsync(String SubscriptionID, String CertificatePath)
        {
            _StorageAccountListDelegate.BeginInvoke(SubscriptionID, CertificatePath, new AsyncCallback(GetStorageAccountListCallBack), new object());
            

        }
        private void GetStorageAccountListCallBack(IAsyncResult ar)
        {
            try
            {
                List<Entities.Storage_Account.StorageAccount> list = _StorageAccountListDelegate.EndInvoke(ar);
                OnGetStorageAccountListCompleted(new ServiceControllerEventArgs(){ StorageAccountList=list,error=null});
                
            }
            catch (Exception ex)
            {
                OnGetStorageAccountListCompleted(new ServiceControllerEventArgs() {  error = ex });
                
            }
        }

    }
}
